package com.camtc.camcenter.config.provider;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.camtc.camcenter.bean.dto.LoginDto;
import lombok.SneakyThrows;
import org.apache.commons.io.IOUtils;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets;

/**
 * JWT身份验证提供者
 * 用于用户登陆后，生成对应的JWT令牌密钥
 *
 * @author
 * @date
 */
public class JwtAuthenticationProvider extends DaoAuthenticationProvider {

    /**
     * @param userDetailsService 用户服务
     */
    public JwtAuthenticationProvider(UserDetailsService userDetailsService) {
        setUserDetailsService(userDetailsService);
        // 密码加密
        setPasswordEncoder(new BCryptPasswordEncoder());
    }
}
